home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / C / MakeIndex < prev    next >
Text File  |  1997-12-16  |  7KB  |  195 lines

  1. /* MakeIndex
  2.     Hacked by Andy Macklin to produce a sort of index of doc/guide files.
  3.     My version of grep uses the following syntax...
  4.     usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]
  5.  
  6.         Requirements:   grep
  7.                         sort
  8.                         copy
  9.                         searchguide (optional)
  10.                         same syntax as buildindex  (optional)
  11.  
  12. */
  13.  
  14. buildidx='Y' /*Change to 'Y' for an all in one script ;) */
  15. SGUIDE='N'   /*Change to 'Y' for an automatic search button in the docs guide file */
  16.  
  17. address command
  18.  
  19. Volume = left(pragma('D'),pos(':',pragma('D')))
  20.  
  21. /* Clear icon position */
  22. 'nopos' Volume'disk nodd'
  23.  
  24. /* defines and such */
  25.         /* GREP CALL */
  26. GREPCALL = "grep"
  27.         /* GREP HELP CALL */
  28. GREPHELP = "grep -h"
  29.         /* Where's the CUCD index? */
  30. IDXLOC = Volume'CDsupport/CUCD.index'
  31.         /* Where's the finished guide to go to?*/
  32. outfile = Volume'CDsupport/Docs.guide'
  33.         /* Path to MultiView */
  34. MView = Volume'Utilities/MultiView'
  35.         /* Extensions to search for */
  36. Extensions = 'guide|doc|dok|txt|text|asc|man|readme'
  37.  
  38. if buildidx='Y' then do
  39.     /* NB the column format is important for the sort fuction later */
  40.     'delete >NIL:' outfile    /* Otherwise the guide will contain a reference to itself */
  41.     'list' Volume'CUCD/(CDROM|Demos|Games|Graphics|Magazine|Online|Previews|Programming|Readers|Sound|Utilities) all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  42. /*
  43.     'list' Volume'CUCD/CDROM all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  44.     'list' Volume'CUCD/Demos all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  45.     'list' Volume'CUCD/Games all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  46.     'list' Volume'CUCD/Graphics all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  47.     'list' Volume'CUCD/Magazine all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  48.     'list' Volume'CUCD/Online all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  49.     'list' Volume'CUCD/Previews all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  50.     'list' Volume'CUCD/Programming all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  51.     'list' Volume'CUCD/Readers all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  52.     'list' Volume'CUCD/Sound all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  53.     'list' Volume'CUCD/Utilities all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  54. */
  55.     end
  56.  
  57. grepfile = "t:grepoutput." || Pragma("i")
  58. agfile = "t:grepguide." || Pragma("i")
  59. CR      = d2c(10)
  60. TAB     = d2c(9)
  61.  
  62. /* setup the output file - we need this first so we can show errors in it */
  63. IF Open(agfp,agfile,'w') = 0 THEN DO
  64.         SAY "Couldn't create amigaguide file ("||agfile||")"
  65.         EXIT 20
  66.         END
  67.  
  68. call writeln(agfp,'@DATABASE "CD docs"')
  69. call writeln(agfp,'@REMARK created by Andys MakeIndex v2 :)')
  70. call writeln(agfp,'')
  71. call writeln(agfp,'@NODE Main "DOCS & GUIDES"')
  72. call writeln(agfp,'')
  73.  
  74. /* Put a search button (needs searchguide in the CDs path) */
  75. if SGUIDE='Y' then do
  76. call writeln(agfp,'@{" Search " SYSTEM "RUN SearchGuide '||substr(outfile,pos(':',outfile)+1)||'" }')
  77. call writeln(agfp,'')
  78. end
  79.  
  80. SIGNAL ON FAILURE
  81. ADDRESS COMMAND
  82. 'delete >NIL:' grepfile
  83. do until Extensions = ''
  84.     parse var Extensions ext '|' Extensions
  85.     GREPCALL '-F .'ext IDXLOC '>>' grepfile
  86.     end
  87. 'rename' grepfile ' to ' grepfile||'.old'
  88. 'sort' grepfile||'.old' grepfile 'colstart 37'
  89. SIGNAL OFF FAILURE
  90.  
  91. IF Open(grepfp,grepfile,'r') = 0 THEN DO
  92.         CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
  93.         END
  94.  
  95. /*************************************************************************
  96. **  Format of Grep output
  97. **  =====================
  98. **
  99. **HTMLit!.guide                 CUCD4:Magazine/WiredWorld/HTMLit!/HTMLit!.guide
  100. **DemosOfTheWorld.guide         CUCD4:CUCD/Demos/DemosOfTheWorld/DemosOfTheWorld.guide
  101. **mc12.guide                    CUCD4:CUCD/Demos/Malevolent_Creations/mc12.guide
  102. **iml-Feb71.guide               CUCD4:CUCD/Graphics/Imagine/iml-Feb71.guide
  103. **Dust.guide                    CUCD4:CUCD/Graphics/Imagine/Dust/Docs/Dust.guide
  104. **DustEnglish.guide             CUCD4:CUCD/Graphics/Imagine/Dust/Docs/DustEnglish.guide
  105. **IM_Organizer.guide            CUCD4:CUCD/Graphics/Imagine/IM_Organiser/IM_Organizer.guide
  106. **TextureStudio.guide           CUCD4:CUCD/Graphics/Imagine/TextureStudio/Docs/TextureStudio.guide
  107. **ncFTPevents.guide             CUCD4:CUCD/Online/ThorStuff/Programs/ncFTPevents/Thor/docs/ncFTPevents.guide
  108. **
  109. ****************************************************************************/
  110.  
  111. line = ReadLn(grepfp)
  112. IF EOF(grepfp) THEN DO
  113.         call close(grepfp)
  114.         say 'No files found'
  115.         exit 10
  116.         END
  117.  
  118.  
  119.         CALL Pragma('W','n')            /* turn off dos requesters */
  120.  
  121. DO WHILE ~EOF(grepfp)
  122.         /* START BY LOOKING FOR FILENAMES */
  123.         currentfile = Strip(Left(line,Length(Word(line,1))),"B")
  124.         location = strip(right(line,length(line)-length(word(line,1))),"B")
  125.         if right(currentfile,5) ='guide' then
  126.         do
  127.             node='/main'
  128.             action='link "'
  129.         end
  130.         else
  131.         do
  132.             node=''
  133.             action='system "'MView' '
  134.         end
  135.         endif
  136.         call writeln(agfp,'@{" 'currentfile left('',33-length(currentfile))' "' action||location||node'" }   'substr(location,pos(':',location)+1))
  137.         line = ReadLn(grepfp)
  138.                 END
  139.  
  140. call WriteLn(agfp,'@ENDNODE')
  141.  
  142. call Close(grepfp)
  143. call Close(agfp)
  144.  
  145.        CALL Pragma('W','w')            /* turn dos requesters back on */
  146.  
  147. address command
  148. 'copy' agfile outfile
  149. 'delete >NIL:' grepfile
  150. 'delete >NIL:' grepfile||'.old'
  151. 'delete >NIL:' agfile
  152.  
  153. EXIT
  154.  
  155. FAILURE:
  156. ERROR:
  157.         errRC = RC
  158.         CALL Close(grepfp)
  159.         CALL HandleError("Grep Failure:"|| CR || "    " || FullCommand ,grepfile)
  160.         EXIT
  161.  
  162. /***************************************************/
  163. HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
  164.  
  165.         ErrorText = arg(1)
  166.         ErrorFile = arg(2)
  167.  
  168.         call writeln(agfp,'-=-=-=-=-=-=-=-=-=  E R R O R  =-=-=-=-=-=-=-=-=-')
  169.         call writeln(agfp,ErrorText)
  170.         call writeln(agfp,' ')
  171.  
  172.         IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
  173.                 call writeln(agfp,"Response:")
  174.                 ADDRESS COMMAND GREPHELP '>>'ErrorFile
  175.                 Open('errorfp',ErrorFile,'r')
  176.                 DO WHILE ~EOF('errorfp')
  177.                         call writeln(agfp,"    " || ReadLn('errorfp'))
  178.                         END
  179.                 call close('errorfp')
  180.                 END
  181.  
  182.         call writeln(agfp,"")
  183.         call writeln(agfp,"Current Path:")
  184.         call writeln(agfp,"    "||Pragma("D"))
  185.         call writeln(agfp,'@ENDNODE')
  186.  
  187.         call close(agfp)
  188.  
  189.         IF Exists(grepfile) THEN Delete(grepfile)
  190.         Delete(agfile)
  191.  
  192.         EXIT 20
  193. RETURN
  194.  
  195.